<?php
namespace Act\Os;
use Lib\ErrorMesssage;
use Lib\Page;
use Lib\Common;
class Menus extends Backend{
	public function doGet(){
		$method = get('method');
		$menu_id = get('menu_id',0,'absint');
		$module_id = get('module_id',0,'absint');
		$menu_name = get('menu_name','','htmlspecialchars');
		
		$menu_url_mod = model('#MenuUrl','adm_');

		$count = $menu_url_mod->searchCount($module_id,$menu_name);
		$page = new Page($count,self::PAGE_SIZE);
		$menus = $menu_url_mod->search($module_id,$menu_name,$page->offset,$page->size);

		$module_options_list = model('#Module','adm_')->getModuleForOptions ();
		$module_options_list[0]="全部";
		ksort($module_options_list);

		$this->display('index.php',array(
			'page_no' => $page->page_no,
			'menus' => $menus,
			'page_html' => $page->show(),
			'module_options_list' => $module_options_list,
			'admin_action_confirm'  => Common::renderJsConfirm("icon-remove"),
		));
	}

	public function doDelete(){
		$menu_id = get('menu_id',0,'absint');
		$menu = model('#MenuUrl','adm_')->getMenuById($menu_id);
	
		if(intval($menu_id) <= 100){
			$this->error(ErrorMessage::CAN_NOT_DELETE_SYSTEM_MEN,'os/menus');
		}else{
			$result = model('#MenuUrl','adm_')->delMenu ( $menu_id );	
			if ($result) {
				$this->sysLog( session('user_info')['user_name'], 'DELETE', 'MenuUrl' ,$menu_id, json_encode($menu) );
				return $this->success ('已将菜单链接删除','os/menus');
			}else{
				return $this->error("error");
			}
		}
	}
}